#ifndef CETRIS_H
#define CETRIS_H

#include <QMainWindow>
#include <array>
#include <QTimer>

#include "dao.h"
using block_array = std::array<std::array<uint8_t, 4>, 4>;
QT_BEGIN_NAMESPACE

namespace Ui {
    class cetris;
}

QT_END_NAMESPACE

class cetris : public QMainWindow {
    Q_OBJECT

public:
    explicit cetris(QWidget* parent = nullptr);

    ~cetris() override;

    void paintEvent(QPaintEvent* event) override;

    void init_block();

    void init_temp_block() noexcept;

    void create_block();

    bool game_has_over();

public slots:
    void block_update();

protected:
    void keyPressEvent(QKeyEvent* event) override;

private:
    void init_rect(int i);

    void block_down_shift();
    void block_left_shift();
    void block_right_shift();

    Ui::cetris* ui;

    std::array<QRect, 4> blocks;
    std::array<std::array<uint8_t, 12>, 15> background{0};
    block_array temp_block{0};
    unsigned int score{0};
    int type{0};

    QTimer* timer;

    int speed{700};

    bool game_started{false};
    bool cur_over{false};
    bool skip{false};
};
#endif // CETRIS_H
